<template>
  <div>
    <button @click="jia">+1</button>
    <button>{{ num }}</button>
    <button @click="jian">-1</button>
  </div>
</template>

<script>
import { ref } from "vue";
export default {
  setup() {
    let num = ref(0);
    // 点击数量增加
    function jia(params) {
      num.value++;
    }
    // 数量减少
    function jian() {
      num.value--;
      if (num.value <= 0) {
        num.value = 0;
      }
    }
    return {
      num,
      jia,
      jian,
    };
  },
};
</script>

<style lang="scss" scoped></style>
